home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 85 / CD-ROM 85 / CD-ROM 85.iso / perso / scr / SCR12.exe / {app} / wave_main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-01-28  |  3.8 KB  |  181 lines

  1. unit wave_main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   Tmainscreen = class(TForm)
  11.     Timer1: TTimer;
  12.     Label1: TLabel;
  13.     procedure Timer1Timer(Sender: TObject);
  14.     procedure FormPaint(Sender: TObject);
  15.     procedure FormHide(Sender: TObject);
  16.     procedure FormShow(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.     procedure saverout(var Msg:TMsg; var Handled:boolean);
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   mainscreen: Tmainscreen;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. uses
  32.   smgrafd;
  33.  
  34. const
  35.   pp=4;
  36.  
  37. var
  38.   dc:hdc;
  39.   crs:Tpoint;
  40.   xmax,ymax:integer;
  41.   desk:tbitmap;
  42.   py:integer;
  43.   lijn:tbitmap;
  44.   dd:integer;
  45.   cc:array[-8..1024] of integer;
  46.   kk:array[0..255,-8..1024] of byte;
  47.  
  48. procedure Tmainscreen.saverout(var Msg : TMsg; var Handled : boolean);
  49. var
  50.   done : boolean;
  51. begin
  52.   if Msg.message = WM_MOUSEMOVE then
  53.     done := (Abs(LOWORD(Msg.lParam) - crs.x) > 5) or
  54.             (Abs(HIWORD(Msg.lParam) - crs.y) > 5)
  55.   else
  56.     done := (Msg.message = WM_KEYDOWN) or (Msg.message = WM_ACTIVATE) or
  57.             (Msg.message = WM_ACTIVATEAPP) or (Msg.message = WM_NCACTIVATE);
  58.   if done then
  59.   begin
  60.     releasedc(0,dc);
  61.     Close;
  62.   end;
  63. end;
  64.  
  65. procedure Tmainscreen.Timer1Timer(Sender: TObject);
  66.  
  67. var
  68.   ll,ld:prgbarray;
  69.   x,x2,y,tt:integer;
  70.  
  71. begin
  72.   ll:=prgbarray(lijn.scanline[0]);
  73.   y:=py;
  74.   for tt:=-8 to ymax div pp+8 do
  75.   begin
  76.     if (y>-1) and (y<ymax) then
  77.     begin
  78.       ld:=prgbarray(desk.scanline[y]);
  79.       for x:=0 to xmax -1 do
  80.       begin
  81.         x2:=x+cc[tt];
  82.         if x<0 then inc(x2,xmax);
  83.         if x2>=xmax then dec(x2,xmax);
  84. //        ll[x]:=ld[x2];
  85.         with ll[x] do
  86.         begin
  87.           rgbTred:=kk[ld[x2].rgbTred,tt];
  88.           rgbTgreen:=kk[ld[x2].rgbTgreen,tt];
  89.           rgbTblue:=kk[ld[x2].rgbTblue,tt];
  90.         end;
  91.       end;
  92.       canvas.draw(0,y,lijn);
  93.     end;
  94.     inc(y);
  95.   end;
  96.   inc(py,dd);
  97.   if py>ymax then
  98.   begin
  99.     if random(2)=0 then
  100.     begin
  101.       py:=-ymax div pp;
  102.       dd:=2+random(4);
  103.     end else
  104.       dd:=-2-random(4);
  105.   end;
  106.   if py<-ymax div pp then
  107.   begin
  108.     if random(2)=0 then
  109.     begin
  110.       py:=ymax;
  111.       dd:=-2-random(4);
  112.     end else
  113.       dd:=2+random(4);
  114.   end;
  115. end;
  116.  
  117. procedure Tmainscreen.FormPaint(Sender: TObject);
  118.  
  119. begin
  120.   canvas.draw(0,0,desk);
  121. end;
  122.  
  123. procedure Tmainscreen.FormHide(Sender: TObject);
  124. begin
  125.   application.OnMessage:=nil;
  126.   timer1.enabled:=false;
  127.   showcursor(true);
  128. end;
  129.  
  130.  
  131. procedure Tmainscreen.FormShow(sender: TObject);
  132.  
  133. var
  134.   tmp:tcanvas;
  135.   i,j,tt:integer;
  136.  
  137. begin
  138.   randomize;
  139.   xmax:=screen.width;
  140.   ymax:=screen.height;
  141.   width:=xmax;
  142.   height:=ymax;
  143.   left:=0;
  144.   top:=0;
  145.  
  146.   dc:=getwindowdc(getdesktopwindow);
  147.   tmp:=tcanvas.create;
  148.   tmp.handle:=dc;
  149.   desk:=tbitmap.create;
  150.   desk.pixelformat:=pf24bit;
  151.   desk.width:=xmax;
  152.   desk.height:=ymax;
  153.   desk.canvas.copyrect(rect(0,0,xmax,ymax),tmp,rect(0,0,xmax,ymax));
  154.   dc:=getdc(0);
  155.   tmp.free;
  156.   lijn:=tbitmap.create;
  157.   lijn.width:=xmax;
  158.   lijn.height:=1;
  159.   lijn.pixelformat:=pf24bit;
  160.  
  161.   GetCursorPos(crs);
  162.   Application.OnMessage:=SAverout;
  163.   showcursor(false);
  164.   for tt:=-8 to 1024 do cc[tt]:=0;
  165.   for tt:=0 to ymax div pp do
  166.     cc[tt]:=round(xmax*-(1-cos(tt*pi*pp*2/ymax))*sin(tt*pi*pp*6/ymax)/128);
  167.   for i:=0 to 255 do for tt:=-8 to 1024 do kk[i,tt]:=i;
  168.   for i:=0 to 255 do for tt:=0 to ymax div 4 do
  169.   begin
  170. //    j:=round(i-128*((1-cos(tt*pi*pp*2/ymax))*cos((tt+ymax div 32)*pi*pp*6/ymax)/4));
  171.     j:=round(i-96*((1-cos(tt*pi*pp*2/ymax))*sin((tt-ymax div 32)*pi*pp*6/ymax)/4));
  172.     if j<0 then j:=0;
  173.     if j>255 then j:=255;
  174.     kk[i,tt]:=j;
  175.   end;
  176.   py:=-ymax div 6;
  177.   dd:=3;
  178. end;
  179.  
  180. end.
  181.